package sjtu.pirate.report.simple;

import java.io.IOException;
import java.util.Hashtable;
import java.util.List;

import sjtu.pirate.analyzer.PirateAnalyzer;
import sjtu.pirate.format.FormResult;
import sjtu.pirate.report.ReportTemplate;
import sjtu.pirate.util.FormHelper;

import biz.source_code.miniTemplator.MiniTemplator.TemplateSyntaxException;
/**
 * @author wilbur.ma@qq.com
 * @date 2011.05.31
 */
public class FormIndexTemplate extends ReportTemplate {
	public FormIndexTemplate(String templateFile, String reportDir, PirateAnalyzer analyzer) 
			throws TemplateSyntaxException, IOException {
		super(templateFile, reportDir, "/detail/index.html", analyzer);
	}
	
	@Override
	protected void setTemplateParams() {
		for (String host : analyzer.getResults().keySet()) {
			setVar("host_id", FormHelper.buildHostID(host));
			if (analyzer.hasFailCases(host))
				setVar("host_name_color", "alert_color");
			else
				setVar("host_name_color", "blue_color");
			setVar("host_name", host);
			Hashtable<String, List<FormResult>> resultA = analyzer.getResults().get(host);
			for (String path : resultA.keySet()) {
				String href = FormHelper.buildFormLink(host, path);
				setVar("form_href", href);
				setVar("form_value", path);
				setVar("cases_num", resultA.get(path).size());
				setVar("fail_cases_num", analyzer.getFailCasesNum(resultA.get(path)));
				addBlock("formListBlock");
			}
			addBlock("indexBlock");
		}
	}
}
